import 'package:erp/data/http/dio_client.dart';
import 'package:get/get.dart';

class ProcessApi {
  /// 查询流程模板
  static Future queryFlowTemplate() {
    return Get.find<DioClient>().get("/process/selectEnabledProcessType");
  }

  /// 查询待办流程
  static Future queryFlowTodo(
    Map<String, dynamic> params,
    int pageNo, {
    int? pageSize = 10,
  }) {
    return Get.find<DioClient>().post(
      "/process/pageProcessTodo/${pageNo}/${pageSize}",
      data: params,
    );
  }

  /// 流程查看
  static Future queryFlowSee(Map<String, dynamic> params, int pageNo, {int? pageSize = 10}) {
    return Get.find<DioClient>().post(
      "/process/pageProcessSee/${pageNo}/${pageSize}",
      data: params,
    );
  }

  /// 查询待办流程
  static Future queryFlowChart(String typeCode) {
    return Get.find<DioClient>().get(
      "/process/selectProcessFlowByTypeCode",
      params: {'typeCode': typeCode},
      needTip: true,
    );
  }

  /// 流程提交或保存待办
  static Future applyProcess(String processDTOStr, List<String> paths) {
    return Get.find<DioClient>().postMultipart(
      "/process/applyProcess",
      params: {'processDTOStr': processDTOStr},
      filePaths: paths,
      needTip: true,
    );
  }

  /// 查询流程详情
  static Future getDetail(String processNo) {
    return Get.find<DioClient>()
        .get("/process/selectProcessDetailInfo", params: {'processNo': processNo}, needTip: true);
  }

  /// 查询流程节点审批信息
  static Future getProcessNodeRangeInfo(String typeCode) {
    return Get.find<DioClient>().get("/process/selectProcessNodeRangeInfo", params: {'typeCode': typeCode});
  }

  /// 删除流程
  static Future deleteProcessById(int id) {
    return Get.find<DioClient>().delete('/process/deleteProcessById', params: {'id': id}, needTip: true);
  }

  // 查询当前处理节点
  static Future selectNearHandleProcessHandleByProcessNo(String processNo) {
    return Get.find<DioClient>()
        .get('/process/selectNearHandleProcessHandleByProcessNo', params: {'processNo': processNo});
  }

  static Future saveProcessHandle(dynamic handle) {
    return Get.find<DioClient>().post('/process/saveProcessHandle', data: handle, needTip: true);
  }

  // delete process file
  static Future deleteProcessFileById(int id) {
    return Get.find<DioClient>().delete("/process/deleteProcessFileById", params: {"id": id});
  }
}
